<?php
/**
 * 银行账户
 */
require_once("../global.inc.php");

class SysBankClass extends SystemFrameWork{
	/**
	 * 银行账户对象
	 *
	 * @var obj
	 */
	var $obj_bank;
	/**
	 * 公司对象
	 *
	 * @var obj
	 */
	var $obj_company;
	/**
	 * 联系人对象
	 *
	 * @var obj
	 */
	var $obj_customer;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $obj_validate;
	/**
	 * 分页对象
	 *
	 * @var obj
	 */
	var $obj_page;
	
	function main(){
		/**
		 * 客户银行账户
		 */
		if (!is_object($this->obj_bank)){
			require_once ("bank.class.php");
			$this->obj_bank = new BankClass();
		}
		/**
		 * 公司
		 */
		if (!is_object($this->obj_company)){
			require_once ("company.class.php");
			$this->obj_company = new CompanyClass();
		}
		/**
		 * 联系人
		 */
		if (!is_object($this->obj_customer)){
			require_once ("customer.class.php");
			$this->obj_customer = new CustomerClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->obj_validate)){
			require_once("commonvalidate.class.php");
			$this->obj_validate = new CommonValidate();
		}
		/**
		 * 初始化分页类
		 */
		if (!is_object($this->obj_page)){
			require_once("commonpage.class.php");
			$this->obj_page = new CommonPage();
		}
		
		switch($this->_input['action']){
			case "ajax_list":
				$this->_ajax_list();
				break;
            case 'list':
                $this->_list();
                break;
			case "save":
				$this->_save();
				break;
			case "update":
				$this->_update();
				break;
			case "del":
				$this->_del();
				break;
			default:
				$this->_list();
		}
	}
	/**
	 * 列表
	 */
	function _list(){
		$this->_ajax_list();
	}
	
	/**
	 * ajax类表
	 */
	function _ajax_list(){
		$objId = $this->_input["objId"];
		$objType = $this->_input["objType"];
		if ($objType == 1) { //公司
			$obj_array = $this->obj_company->getCompany($objId);
		}else { //联系人
			$obj_array = $this->obj_customer->getCustomer($objId);
		}
		//搜索条件
		$condition = " where object_id='".$objId."' and object_type='".$objType."' and status='1' order by id desc ";

		//信息列表
		$this->obj_page->pagebarnum(10);
		$this->obj_page->nowindex = $this->_input['curpage']?$this->_input['curpage']:1;
		$bank_array = $this->obj_bank->listBank($condition,$this->obj_page);
		
		//对时间进行格式化
		if (is_array($bank_array)){
			for ($i=0;$i<count($bank_array);$i++){
				$bank_array[$i]['create_time'] = @date("Y-m-d", $bank_array[$i]['create_time']);
			}
		}

		$page_list = $this->obj_page->show(2);
		/**
		 * 页面输出
		 */
		$this->output("curpage", $this->obj_page->nowindex);
		$this->output('bank_array',$bank_array);
		$this->output('page_list',$page_list);
		$this->output('objType',$objType);
		$this->output('objId',$objId);
		$this->output('obj_array',$obj_array);
		$this->showpage('bank.list');
	}
	/**
	 * 信息添加
	 */
	function _save(){
		$objId = intval($this->_input['objId']);
		$objType = intval($this->_input['objType']);
		
		$value_array = array();
		$value_array['object_id'] = $objId;
		$value_array['object_type'] = $objType;
		$value_array['realname'] = trim($this->_input["realname"]);  //名称
		$value_array['cardno'] = trim($this->_input["cardno"]);  //帐号
		$value_array['bankname'] = trim($this->_input["bankname"]);  //银行全称
		$value_array['bankaddress'] = trim($this->_input["bankaddress"]);  //地址
		$value_array['create_id'] = $_SESSION['s_admin']['id'];  //创建者ID
		$value_array['create_time'] = time();  //创建时间
		$value_array['status'] = 1;  //状态
		$result = $this->obj_bank->addBank($value_array);
			
		if ($result != true){
			$this->redirectPath('error','./bank.manage.php?action=list&objId='.$objId.'&objType='.$objType,'添加账户信息失败！',1);
		}else {
			//记录操作日志
			SystemPowerClass::addSysLog('账户信息->添加账户信息');
			$this->redirectPath('error','./bank.manage.php?action=list&objId='.$objId.'&objType='.$objType,'添加账户信息成功！',1);
		}
		
	}
	
	/**
	 * 保存修改
	 */
	function _update(){
		/**
		 * 信息验证
		 */
//		$this->obj_validate->validateparam = array(
//			array("input"=>$this->_input["id"], "require"=>"true","validator"=>"Number", "message"=>$this->_lang['errSysNNewsIdIsEmpty']),
//			array("input"=>$this->_input["txttitle"], "require"=>"true", "message"=>$this->_lang['errSysNNewsNameIsEmpty']),
//			array("input"=>$this->_input["news_c_id"], "require"=>"true","validator"=>"Number", "message"=>$this->_lang['errSysNNewsClassIsEmpty']),
//			array("input"=>$this->_input["txtsort"], "require"=>"true","validator"=>"Number", "message"=>$this->_lang['errSysNNewsSortIsWrong']),		
//		);
//		$error = $this->obj_validate->validate();
//		if ($error != ''){
//			$this->redirectPath('error','',$error,1);
//		}else {
			$objId = $this->_input["objId"];
			$objType = $this->_input["objType"];
		
			$value_array = array();
			$value_array['id'] = $this->_input["hidId"];
			$value_array['realname'] = trim($this->_input["realname"]);  //名称
			$value_array['cardno'] = trim($this->_input["cardno"]);  //帐号
			$value_array['bankname'] = trim($this->_input["bankname"]);  //银行全称
			$value_array['bankaddress'] = trim($this->_input["bankaddress"]);  //地址
			$result = $this->obj_bank->updateBank($value_array);
			
			if ($result != true){
				$this->redirectPath('error','./bank.manage.php?action=list&objId='.$objId.'&objType='.$objType,'更新账户信息失败！',1);
			}else {
				//记录操作日志
				SystemPowerClass::addSysLog('账户信息->更新账户信息');
				$this->redirectPath('error','./bank.manage.php?action=list&objId='.$objId.'&objType='.$objType,'更新账户信息成功！',1);
			}
//		}
	}
	
	/**
	 * 删除信息
	 */
	function _del(){
		$objId = $this->_input["objId"];
		$objType = $this->_input["objType"];
		
		if (is_array($this->_input['id'])){
			foreach ($this->_input['id'] as $v) {
				$this->obj_bank->delBank($v);
			}
			//记录操作日志
			SystemPowerClass::addSysLog('账户信息->删除账户信息');
			$this->redirectPath('error','./bank.manage.php?action=list&objId='.$objId.'&objType='.$objType,'删除账户信息成功！',1);
		}else {
			$this->redirectPath('error', './bank.manage.php?action=list&objId='.$objId.'&objType='.$objType, '删除账户信息失败！', 1);
		}
	}
}
$bank = new SysBankClass();
$bank->main();
unset($bank);
?>